package com.stx.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import com.stx.dao.DormDao;
import com.stx.domain.Dorm;

@Repository
public class DormDaoImpl implements DormDao {
	/*@Resource
	private Dorm dorm;*/
	@Resource
	private JdbcTemplate jt;

	public List<Dorm> selectDorm(String name) {
		String sql ="select d.name,count(s.d) from s right outer join d on s.d=d.name where d.name like '"+name+"____' group by d.name order by d.name";
		
		Object[] obj = null;
		List<Dorm> list = jt.query(sql, obj, new info());
		return list;
	}

	class info implements RowMapper {

		@Override
		public Object mapRow(ResultSet rs, int arg1) throws SQLException {
			Dorm dorm=new Dorm();
			dorm.setName(rs.getString("name"));
			dorm.setPup(rs.getString("count(s.d)"));

			return dorm;
		}
	}
}
